package org.hdax.easybuyorder.controller;

import org.hdax.easybuyorder.client.UserClient;
import org.hdax.easybuyorder.dao.OrderDao;
import org.hdax.easybuyorder.entity.EasybuyOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/order")
public class OrderService {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private UserClient userClient;

    @GetMapping("{id}")
    public Map<String,Object> findById(@PathVariable Integer id){
        Map<String,Object> map = new HashMap<>();
        EasybuyOrder order = orderDao.findById(id).get();
        map.put("order",order);
        map.put("user",userClient.findById(order.getUserId()));
        return map;
    }
}
